home *** CD-ROM | disk | FTP | other *** search
/ El Mac 9 / El Mac 9.iso / Shareware / Demos / Igor Demo Pro / 1 PutContentsIn Igor Pro Folder / WaveMetrics Procedures / Utilities / String Utilities / Name Checking < prev    next >
Encoding:
Text File  |  1994-02-18  |  1.3 KB  |  73 lines  |  [TEXT/IGR0]

  1.  
  2. | return truth numeric value given by c represents an alphabetic character
  3. |
  4. Function IsAlpha(c)
  5.     Variable c
  6.     
  7.     Variable t= (c>=65) %& (c<=90)
  8.     return t %| ( (c>=97) %& (c<=122))
  9. end
  10.  
  11. | return truth numeric value given by c represents a numeric character
  12. |
  13. Function IsNumeric(c)
  14.     Variable c
  15.     
  16.     return  (c>=48) %& (c<=57)
  17. end
  18.  
  19. | given a proposed name for an object (wave or something else) return:
  20. |    0 -- no problem
  21. |    1 -- didn't start with a letter
  22. |    2 -- too long
  23. |    3 -- illegal char in name
  24. |    negative value -- already exists. value is minus the  code returned by exists()
  25. |
  26. Function CheckObjName(s,isWave)
  27.     String s; Variable isWave
  28.     
  29.     if( !IsAlpha(char2num(s[0])) )
  30.         return 1
  31.     endif
  32.     Variable n=strlen(s)
  33.     if( isWave )
  34.         if( n > 18 )
  35.             return 2
  36.         endif
  37.     else
  38.         if( n > 31 )
  39.             return 2
  40.         endif
  41.     endif
  42.     Variable i=0,ch
  43.     do
  44.         i+=1
  45.         if( i>=n)
  46.             break
  47.         endif
  48.         ch= char2num(s[i])
  49.         if( !( IsAlpha(ch) %| IsNumeric(ch) %| (ch==95) ) )
  50.             return 3
  51.         endif
  52.     while(1)
  53.     return -exists(s)
  54. end
  55.  
  56. | Given a base name, append digits until a name is found that
  57. | does not conflict with other object names
  58. |
  59. Function/S FormUniqueName(base)
  60.     String base
  61.     
  62.     Variable i=0
  63.     String s
  64.     do
  65.         sprintf s,"%s%d",base,i
  66.         if( exists(s) == 0 )
  67.             return s
  68.         endif
  69.         i+=1
  70.     while(i<10000)
  71.     return "*****"    | should never happen
  72. End
  73.